<?php

class Damages_Methods_Request_GetBrandDealers extends Damages_Methods_Request {

  /**
   *
   * @var int
   */
  public $brandId;

  public function __construct($params) {
    parent::__construct($params);
    $this->brandId = (int) $params->brandId;
  }

  public function process() {
    // pobranie listy dealerów dla brandu
    if (!Damages_Auth::getInstance()->checkPermission(array(Damages_Auth::PERMISSION_LS, Damages_Auth::PERMISSION_ADMIN)))
      throw new Damages_Exception_App(Damages_Codes::ACCESS_DENIED);
    $dealers = DamagesDealersQuery::create()->filterByDictBrandId($this->brandId)->find();
    if ($dealers->isEmpty())
      throw new Damages_Exception_App(Damages_Codes::NO_DEALERS_FOR_BRAND, array($this->brandId));
    $response = new Damages_Methods_Response_GetBrandDealers(true);
    $response->setData($dealers);
    return $response;
  }

}